package kubayaxi.video.client.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import kubayaxi.video.client.response.banner.BannerListVO;
import kubayaxi.video.client.service.IBannerService;
import kubayaxi.video.mybatis.auto.dao.BannerMapper;
import kubayaxi.video.mybatis.auto.model.Banner;
import kubayaxi.video.service.base.common.enums.BannerStatusEnum;
import kubayaxi.video.service.base.common.enums.DeleteEnum;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: kubayaxi_video_back
 * @description:
 * @author: Mr.lin
 * @create: 2023-01-01 22:01
 **/
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements IBannerService {

	/**
	 * 查询轮播图集合
	 * @return
	 */
	@Override
	public List<BannerListVO> bannerList() {
		//根据sortNum取5张
		List<Banner> bannerList = this.list(new LambdaQueryWrapper<Banner>()
				.eq(Banner::getDeleteStatus, DeleteEnum.NOT_DELETED.getCode())
				.eq(Banner::getBannerStatus, BannerStatusEnum.YES.getCode())
				.orderByDesc(Banner::getSortNum)
				.orderByDesc(Banner::getCreatedTime)
				.last("limit 5"));
		return bannerList.stream().map(item -> BannerListVO.builder()
				.id(item.getId())
				.url(item.getUrl())
				.vId(item.getVId())
				.build())
				.collect(Collectors.toList());
	}
}
